<template>
  <div class="wrapper">
    <el-form>
      <el-form-item label="选择图片">
        <input type="file" placeholder="请选择图片" ref="file" @change="fileChange"/>
        <el-input type="file" v-model="filePath" placeholder="请选择图片" ref="file2" @change="fileChange2"/>
      </el-form-item>
    </el-form>
    <el-row>
      <span>{{file}}----{{file.name}}</span>
    </el-row>
    <el-row>
      <!--suppress HtmlUnknownTarget -->
      <img :alt="imageSrc" :src="imageSrc"/>
    </el-row>
    <el-button @click="upload" :loading="loading">上传图片</el-button>
    <el-button @click="fresh">刷新</el-button>
    <el-button @click="show2">查看文件二</el-button>
    <el-progress :percentage="progress"/>
  </div>
</template>

<script>
import { uploadCollectionFile } from '@/api/ApiFileCollection'

export default {
  name: 'PageTest1',
  components: {},
  data () {
    return {
      file: '',
      filePath: '',
      loading: false,
      progress: 10,
      imageSrc: ''
    }
  },
  methods: {
    fresh () {
    },
    fileChange (e) {
      this.file = e.target.files[0]
    },
    fileChange2 () {
      this.$message.warning('file2change')
      this.file = this.$refs.file2.$el.firstElementChild.files[0]
    },
    show2 (e) {
    },
    upload () {
      const vm = this
      if (!this.file) {
        this.$message.warning('请先选择上传文件')
        return
      }
      uploadCollectionFile(vm.file, '', (val) => {
        vm.progress = val.total.percent
      }, () => {
      })
    }
  },
  watch: {
    file () {
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
